package com.ruoyi.project.system.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.framework.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 用户信息对象 sys_user
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
public class SysUser extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户账号（手机号）
     */
    @Excel(name = "用户账号", readConverterExp = "手机号")
    private String userName;

    /**
     * 密码
     */
    @Excel(name = "密码")
    private String password;

    /**
     * 昵称
     */
    @Excel(name = "昵称")
    private String nickName;

    /**
     * 用户邮箱
     */
    @Excel(name = "用户邮箱")
    private String email;

    /**
     * 用户性别（0男 1女 2未知）
     */
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    private String sex;

    /**
     * 微信用户openId
     */
    @Excel(name = "微信用户openId")
    private String openId;

    /**
     * 最后登录IP
     */
    @Excel(name = "最后登录IP")
    private String loginIp;

    /**
     * 最后登录时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date loginDate;

    /**
     * 会员等级
     */
    @Excel(name = "会员等级")
    private String grade;

    /**
     * 受益父级
     */
    @Excel(name = "受益父级")
    private String parent;

    /**
     * 注册父级
     */
    @Excel(name = "注册父级")
    private String registerParemt;

    /**
     * 转账姓名
     */
    @Excel(name = "转账姓名")
    private String alipayName;

    /**
     * 转账账号
     */
    @Excel(name = "转账账号")
    private String alipayAccount;

    @Excel(name = "启用秒到账（0不启用；2启用）")
    private String enableTc;

    @Excel(name = "单次提现最大免批额")
    private BigDecimal maxTc;

    /**
     * 角色
     */
    @Excel(name = "角色")
    private Long roleId;

    /**
     * 帐号状态（0正常；1停用）
     */
    @Excel(name = "帐号状态", readConverterExp = "0=正常；1停用")
    private String status;

    @Excel(name = "微信支付", readConverterExp = "0=正常；1停用")
    private String wxpayh5;

    /**
     * 删除标志（0代表存在；2代表删除）
     */
    private String delFlag;

    public SysUser() {
    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    public SysUser(Long userId, String grade) {
        this.userId = userId;
        this.grade = grade;
    }

    public SysUser(Long userId, String alipayName, String alipayAccount) {
        this.userId = userId;
        this.alipayName = alipayName;
        this.alipayAccount = alipayAccount;
    }

    public boolean isAdmin() {
        return isAdmin(this.roleId);
    }

    public static boolean isAdmin(Long roleId) {
        return roleId != null && 1L == roleId;
    }

}
